'''
最开始的aptos数据处理的代码出现了问题，这里做一个hotfix.
问题：最开始的aptos的orignal path写的的orignal_dir，没有具体到路径
'''
data_ori_dir= "/data0/zhangpinglu/gy/Dataset/public_dataset"
processed_dir= "/data0/zhangpinglu/gy/Dataset/public_processed"
dataset_name="APTOS"


import os
import json

ori_dir=os.path.join(data_ori_dir,dataset_name)
# 1. 找到annotations.json
with open(os.path.join(processed_dir,dataset_name,"annotations.json"),"r") as f:
    ann=json.load(f)
cnt=0
for image_name,data in ann.items():
    rel_ori_path = data.get("original_path") 
    ori_name= image_name.split("_")[-1]
    ori_path=os.path.join(ori_dir,rel_ori_path,ori_name)
    
    if not os.path.exists(ori_path):
        raise FileNotFoundError(f"原始图片不存在: {ori_path}")
    cnt+=1
    data["original_path"]=os.path.join(rel_ori_path,ori_name)
print(f"{cnt}条数据被成功修正")
with open(os.path.join(processed_dir,dataset_name,"annotations.json"),"w") as f:
    json.dump(ann,f,indent=4)
print(f"fix {dataset_name} done!")
    
    